﻿<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <title></title>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shCore.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushCSharp.js"></script>
    <script type="text/javascript" src="../../Content/highlighter/scripts/shBrushXml.js"></script>
    <link type="text/css" rel="stylesheet" href="../../Content/highlighter/styles/shCoreDefault.css" />
    <script type="text/javascript">SyntaxHighlighter.all();</script>
</head>
<body>
    <h3>打印图片bug.</h3>
    <pre class="brush:csharp;">
    private void PrintDocument1_PrintPage(object sender, PrintPageEventArgs e)
    {
        Graphics g = e.Graphics;
        //var setting = e.PageSettings;
        //var bounds = e.PageBounds;
        //var bb = e.MarginBounds;
        e.HasMorePages = false;
        var image= new Bitmap(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "小票.gif"));
        float width = (image.Width)*1f/ solution.X;
        float height = (image.Height)*1f / solution.Y;
        //这里是一个bug，这里用的分辨率是显示屏的分辨率，而非打印机的分辨率。
        //因此需要把打印机的分辨率设置成图片的分辨率。
        image.SetResolution(solution.X,solution.Y);
        //g.DrawImageUnscaled(image,0,0,image.Width,image.Height);
        g.DrawImage(image, 0f, 0f, new RectangleF(0, 0, image.Width, image.Height), GraphicsUnit.Pixel);
    }
    </pre>
</body>
</html>